﻿using CefSharp.Wpf;
using CefSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace demoCefSharp
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            //WebBrowser webBrowser = new WebBrowser();
            //webBrowser.Source = new Uri("http://www.baidu.com");
            //grid01.Children.Add(webBrowser);

            ChromiumWebBrowser webBrowser = new ChromiumWebBrowser();
            //v.Title = "加载本地网页";
            //webBrowser.Name = "加载本地网页";
            //  webBrowser.Address = "http://www.baidu.com";

            //注入c#方法到前端页面 
            webBrowser.JavascriptObjectRepository.Register("csharpTest", new JavascriptCallCSharp(), true, BindingOptions.DefaultBinder);
            webBrowser.JavascriptObjectRepository.ObjectBoundInJavascript += (sender, e) =>
            {
                var name = e.ObjectName;
                System.Diagnostics.Debug.WriteLine($"对象 {e.ObjectName} 绑定成功.");
            };

            webBrowser.Address = "http://www.baidu.com";// AppDomain.CurrentDomain.BaseDirectory + "html/index.html";
            girds.Children.Add(webBrowser);

           


        }
    }
}
